﻿#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//计算器的⼀般实现：
void menu()
{
	printf("**********************************************************\n");
	printf("**************** 1、plus	2、sub	******************\n");
	printf("**************** 3、mul 	4、div	******************\n");
	printf("****************	0、exit		******************\n");
	printf("**********************************************************\n");
}
int plus(int x, int y)
{
	return x + y;
}
int sub(int x, int y)
{
	return x - y;
}
int mul(int x, int y)
{
	return x * y;
}
int div(int x, int y)
{
	return x / y;
}
typedef int (*pf_Arithmetic)(int, int);
int main()
{
	int input = 0;
	pf_Arithmetic p[5] = { 0,plus,sub,mul,div };
	do
	{
		int x = 0;
		int y = 0;
		int ret = 0;
		//主菜单
		menu();
		scanf("%d", &input);
		
		if (input > 0 && input <= 4)
		{
			printf("输入两个数>>>\n");
			scanf("%d %d", &x, &y);
			ret = p[input](x, y);
			printf("结果>>>%d\n", ret);
		}
		else if (input == 0)
		{
			printf("退出计算器\n");
		}
		else
		{
			printf("输入错误，重新输入>>>\n");
		}
	} while (input);
	return 0;
	
}